package com.company.module.controller;

import com.company.module.pojo.TabRole;
import com.company.module.service.TabRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/role")
public class RoleController {

    @Autowired
    TabRoleService tabRoleService;

    @GetMapping("list")
    public String list(){
        return "/list.html";
    }

    @GetMapping("info")
    public String info(@RequestParam("roleName") String roleName,Model model){
        model.addAttribute("name",roleName);
        return "role_info";
    }

    @GetMapping("/get/{roleId}")
    @ResponseBody
    public TabRole getRoleById(@PathVariable("roleId") String roleId){
        TabRole tabRole = tabRoleService.getById(roleId);
        if(tabRole==null){
            tabRole = new TabRole();
            tabRole.setRoleName("角色不存在");
        }else{
            tabRole.setLabel("admin");
            tabRoleService.updateById(tabRole);
        }
        return tabRole;
    }

}
